package com.zmn.plat.admin.controller.orderconfig.orderstock.channel;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.exception.ZmnException;
import com.zmn.plat.model.entity.orderconfig.orderstock.SubmitDutyDateVO;
import com.zmn.plat.model.entity.orderconfig.orderstock.channel.ChannelCloseDayVO;

/**
 * 渠道库存配置
 *
 * @author xiangjunming
 * @since 2020年3月17日16 :49:40
 * @modify 20200324 xiangjunming 创建
 */
@Controller
@RequestMapping("/channel/config/")
public class ChannelConfigCloseModifyController extends ChannelConfigCloseBaseController {

    /**
     * logger 描述此字段
     */
    private Logger logger = LoggerFactory.getLogger(ChannelConfigCloseModifyController.class);

    /**
     * 关闭库存
     *
     * @param vo
     *            描述此参数
     * @return 返回 response dto 描述此返回参数
     * @author xiangjunming
     * @since 20200324 18:18:25
     * @modify 20200324 xiangjunming 创建
     */
    @RequestMapping(value = "closeDays")
    @ResponseBody
    public ResponseDTO closeDays(@RequestBody SubmitDutyDateVO<ChannelCloseDayVO> vo) {
        try {
            vo.setOperator(getMcStaff().getRealName());
            channelConfigCloseBService.closeDays(vo);
        } catch (ZmnException e) {
            return ResponseDTO.fail(e.getMessage());
        } catch (Exception e) {
            logger.error("error:", e);
            return ResponseDTO.fail("ERROR!");
        }
        return ResponseDTO.success();
    }

    /**
     * 开启库存
     *
     * @param ids
     *            描述此参数
     * @return 返回 response dto 描述此返回参数
     * @author xiangjunming
     * @since 20200324 18:18:25
     * @modify 20200324 xiangjunming 创建
     */
    @RequestMapping(value = "openDays")
    @ResponseBody
    public ResponseDTO openDays(@RequestBody List<Integer> ids) {
        try {
            channelConfigCloseBService.openDays(ids, getMcStaff().getRealName());
        } catch (ZmnException e) {
            return ResponseDTO.fail(e.getMessage());
        } catch (Exception e) {
            logger.error("error:", e);
            return ResponseDTO.fail("ERROR!");
        }
        return ResponseDTO.success();
    }
}
